let Mock =require("mockjs")
let data = [
    {id:0,name:"橘子",text:"黄黄的"},
    {id:1,name:"杨桃",text:"像个五角星"},
    {id:2,name:"食品3",text:"食品3无添加剂"},
    {id:3,name:"食品4",text:"食品4无添加剂"},
    {id:4,name:"食品5",text:"食品5无添加剂"},
    {id:5,name:"食品6",text:"食品6无添加剂"},
    {id:6,name:"食品7",text:"食品7无添加剂"},
   

]
// 获取数据
Mock.mock("/api/homefood","get",function(config){
    console.log(config)
    return data
})
// 修改数据
Mock.mock(/\/api\/homefood\/edit\/\d/,"put",function(config){
    console.log(config)
    let arr=config.url.split("/")
    let id = arr.pop()
    let canshu=config.body 
    canshu =JSON.parse(canshu)
    data[id].name=canshu.name
    data[id].text=canshu.text
    return data
})
// 删除数据
Mock.mock(/\/api\/homefood\/\d/,"delete",function(config){
    console.log(config.url)
    let arr= config.url.split("/")
    let id= arr.pop()
    data.splice(id,1)
    data=data.map(function(item,index){
        return {
            id:index,
            name:item.name,
            text:item.text
        }
    })
    return data
})